package com.potenza.business.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.potenza.business.domain.DishesTypeDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.potenza.business.domain.TbDishesType;
import com.potenza.business.service.ITbDishesTypeService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;

/**
 * dishController
 * 
 * @author ruoyi
 * @date 2023-04-21
 */
@RestController
@RequestMapping("/dish_type")
public class TbDishesTypeController extends BaseController
{
    @Autowired
    private ITbDishesTypeService tbDishesTypeService;

    /**
     * 查询dish列表
     */
    @RequiresPermissions("business:dish_type:list")
    @GetMapping("/list")
    public AjaxResult list(TbDishesType tbDishesType)
    {
        List<TbDishesType> list = tbDishesTypeService.selectTbDishesTypeList(tbDishesType);
        return AjaxResult.success(list);
    }

    /**
     * 导出dish列表
     */
    @RequiresPermissions("business:dish_type:export")
    @Log(title = "dish", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbDishesType tbDishesType)
    {
        List<TbDishesType> list = tbDishesTypeService.selectTbDishesTypeList(tbDishesType);
        ExcelUtil<TbDishesType> util = new ExcelUtil<TbDishesType>(TbDishesType.class);
        util.exportExcel(response, list, "dish数据");
    }

    /**
     * 获取dish详细信息
     */
    @RequiresPermissions("business:dish_type:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tbDishesTypeService.selectTbDishesTypeById(id));
    }

    /**
     * 新增dish
     */
    @RequiresPermissions("business:dish_type:add")
    @Log(title = "dish", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbDishesType tbDishesType)
    {
        return toAjax(tbDishesTypeService.insertTbDishesType(tbDishesType));
    }

    /**
     * 修改dish
     */
    @RequiresPermissions("business:dish_type:edit")
    @Log(title = "dish", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbDishesType tbDishesType)
    {
        return toAjax(tbDishesTypeService.updateTbDishesType(tbDishesType));
    }

    /**
     * 删除dish
     */
    @RequiresPermissions("business:dish_type:remove")
    @Log(title = "dish", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbDishesTypeService.deleteTbDishesTypeByIds(ids));
    }


    @GetMapping("/listTree")
    public AjaxResult listTree()
    {
        List<DishesTypeDTO> list = tbDishesTypeService.selectTreeDishesTypeDTO();
        return AjaxResult.success(list);
    }
}
